package cn.study.luckyapp.assembler;

import cn.study.luckyclient.dto.PrizeAddCmd;
import cn.study.luckyclient.dto.PrizeUpdateCmd;
import cn.study.luckyclient.dto.data.PrizeVo;
import cn.study.luckydomain.prize.Inventory;
import cn.study.luckydomain.prize.PrizeEntity;

import java.math.BigDecimal;
import java.time.LocalDateTime;

public class PrizeAssembler {
    public static PrizeVo addPrizeVo(PrizeEntity prizeEntity){
        PrizeVo prizeVo = new PrizeVo();
        prizeVo.setId(prizeEntity.getId());
        prizeVo.setPrizeName(prizeEntity.getPrizeName());
        prizeVo.setInventory(prizeEntity.getInventory().getInventory());
        prizeVo.setMoney(prizeEntity.getMoney());
        prizeVo.setType(prizeEntity.getType());
        prizeVo.setCreateTime(prizeEntity.getCreateTime());
        prizeVo.setCretor(prizeEntity.getCretor());
        prizeVo.setUpdateTime(prizeEntity.getUpdateTime());
        prizeVo.setUpdater(prizeEntity.getUpdater());
        return prizeVo;
    }
    public static PrizeEntity toEntity(PrizeAddCmd prizeAddCmd){
        PrizeEntity prizeEntity = new PrizeEntity();
        prizeEntity.setPrizeName(prizeAddCmd.getPrizeName());
        prizeEntity.setInventory(new Inventory(prizeAddCmd.getInventory()));
        prizeEntity.setMoney(prizeAddCmd.getMoney());
        prizeEntity.setType(prizeAddCmd.getType());
        prizeEntity.setCreateTime(LocalDateTime.now());
        prizeEntity.setCretor("小三");
        prizeEntity.setUpdateTime(LocalDateTime.now());
        prizeEntity.setUpdater("小三");
        return prizeEntity;
    }
    public static PrizeEntity toEntity(PrizeUpdateCmd cmd){
        PrizeEntity prizeEntity = new PrizeEntity();
        prizeEntity.setId(cmd.getId());
        prizeEntity.setPrizeName(cmd.getPrizeName());
        prizeEntity.setInventory(new Inventory(cmd.getInventory()));
        prizeEntity.setMoney(new BigDecimal(cmd.getMoney().toString()));
        prizeEntity.setType(cmd.getType());
        prizeEntity.setUpdateTime(LocalDateTime.now());
        prizeEntity.setUpdater("小三");
        return prizeEntity;
    }
}
